package com.gzcstec.rabbitmq.controller;

import com.gzcstec.rabbitmq.client.MySink;
import com.gzcstec.rabbitmq.client.MySource;
import com.gzcstec.rabbitmq.dataobject.Girl;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/mq")
@EnableBinding(value = {MySource.class})
public class MqController {

    @Autowired
    private AmqpTemplate amqpTemplate;

    @Autowired
    private MySource mySource;

    @RequestMapping("/amqp/send")
    public void send() {
        amqpTemplate.convertAndSend("amdpQueue" , "消息发送");
    }

    @RequestMapping("/amqp/fruit/send")
    public void sendFruit() {
        amqpTemplate.convertAndSend("order" , "fruit" , "fruit消息发送");
    }

    @RequestMapping("/amqp/computer/send")
    public void sendComputer() {
        amqpTemplate.convertAndSend("order" , "computer" , "computer消息发送");
    }

    @RequestMapping("/stream/send")
    public void sendStream() {
        Girl girl = new Girl();
        girl.setName("yien");
        //调用输入管道进行消息的输入
        mySource.output().send(MessageBuilder.withPayload(girl).build());
    }
}
